package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.dto.PageDto;
import com.qf.mapper.DtsAdMapper;
import com.qf.pojo.DtsAd;
import com.qf.service.DtsAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/25 10:57
 */
@Service

public class DtsAdServiceIMpl implements DtsAdService {
    @Autowired
    private DtsAdMapper dtsAdMapper;

    @Override
    public Page<DtsAd> selectPage(PageDto pageDto) {

        return dtsAdMapper.selectPage(new Page<DtsAd>(pageDto.getPage(), pageDto.getLimit()), new QueryWrapper<DtsAd>().orderBy
        (!StringUtils.isEmpty(pageDto.getSort()), "asc".equalsIgnoreCase(pageDto.getOrder()), pageDto.getSort()).
        like(!StringUtils.isEmpty(pageDto.getName()), "name", pageDto.getName()).like(!StringUtils.isEmpty(pageDto.getContent()),"content",pageDto.getContent()).eq("deleted", false) );
    }

    @Override
    public void update(DtsAd dtsAd) {
        dtsAdMapper.updateById(dtsAd);
    }

    @Override
    public void delete(DtsAd dtsAd) {
        dtsAdMapper.updateById(dtsAd);
    }

    @Override
    public void insert(DtsAd dtsAd) {
    dtsAdMapper.insert(dtsAd);
    }

}
